home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / C++ Direct Buffer Access Code / Blitting.sit / Blitting Folder ƒ / PUT IN--“Metrowerks C_C++” ƒ / Personal Library / MacintoshIdioms.h next >
Text File  |  1995-08-04  |  1KB  |  75 lines

  1. // MacintoshIdioms.h, common pieces of code in the form of inline-functions
  2.  
  3. // copyright ⌐ 1995, Macneil Shonle. All rights reserved.
  4.  
  5. #ifndef __MACINTOSHIDIOMS__
  6. #define __MACINTOSHIDIOMS__
  7.  
  8. inline void ButtonDelay(int waitMouseUp =true)
  9. {
  10.     while (!::Button()) ;
  11.     if (waitMouseUp) while (::Button()) ;
  12. }
  13.  
  14. inline void Delay(long howLong)
  15. {
  16.     long dummy;
  17.     ::Delay(howLong, &dummy);
  18. }
  19.  
  20. inline Point& TopLeft(Rect& r)
  21. {
  22.     return ((Point*)&r)[0];
  23. }
  24.  
  25. inline Point& BottomRight(Rect& r)
  26. {
  27.     return ((Point*)&r)[1];
  28. }
  29.  
  30. inline void CenterRect(Rect& rect, const Rect& frame)
  31. {
  32.     ::OffsetRect(&rect, -rect.left, -rect.top);
  33.     ::OffsetRect(&rect, (frame.right - frame.left - rect.right)/2,
  34.         (frame.bottom - frame.top - rect.bottom)/2);
  35. }
  36.  
  37. inline Point MakePoint(short h, short v)
  38. {
  39.     Point pt = {v, h};
  40.     return pt;
  41. }
  42.  
  43. inline Rect MakeRect(short left, short top, short bottom, short right)
  44. {
  45.     Rect r = {top, left, right, bottom};
  46.     return r;
  47. }
  48.  
  49.         // class LittleTimer
  50. class LittleTimer {
  51. public:
  52.     LittleTimer() : startTime(::TickCount()), frames(0) {}
  53.     ~LittleTimer()
  54.     {
  55.         long totalTime = ::TickCount() - startTime;
  56.         totalTime /= 60;
  57.         if (totalTime) {
  58.             Str255 string;
  59.             ::NumToString(frames/totalTime, string);
  60.             ::DebugStr(string);
  61.         }
  62.         else
  63.             ::DebugStr("\pNot enough timed");
  64.     }
  65.     long operator++(int)
  66.     {
  67.         return frames++;
  68.     }
  69.  
  70. private:
  71.     long startTime;
  72.     long frames;
  73. };
  74.  
  75. #endif